<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="币种名称" prop="coinName">-->
<!--        <el-input-->
<!--          v-model="queryParams.coinName"-->
<!--          placeholder="请输入币种名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="简称" prop="shortName">-->
<!--        <el-input-->
<!--          v-model="queryParams.shortName"-->
<!--          placeholder="请输入简称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="币种图片" prop="coinImg">-->
<!--        <el-input-->
<!--          v-model="queryParams.coinImg"-->
<!--          placeholder="请输入币种图片"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="超过多少数量转入冷钱包" prop="outQtyToColdAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.outQtyToColdAddress"-->
<!--          placeholder="请输入超过多少数量转入冷钱包"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="合约地址" prop="contract">-->
<!--        <el-input-->
<!--          v-model="queryParams.contract"-->
<!--          placeholder="请输入合约地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="币种精度 以太坊系列才有" prop="coinDecimal">-->
<!--        <el-input-->
<!--          v-model="queryParams.coinDecimal"-->
<!--          placeholder="请输入币种精度 以太坊系列才有"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="允许充值 0：否 1：是" prop="allowRecharge">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowRecharge"-->
<!--          placeholder="请输入允许充值 0：否 1：是"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="允许提币 0：否 1：是" prop="allowWithdraw">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowWithdraw"-->
<!--          placeholder="请输入允许提币 0：否 1：是"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否允许兑换" prop="allowExchange">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowExchange"-->
<!--          placeholder="请输入是否允许兑换"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="对外转出手续费" prop="outWithdrawFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.outWithdrawFee"-->
<!--          placeholder="请输入对外转出手续费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="提币最大限制" prop="maxOutQty">-->
<!--        <el-input-->
<!--          v-model="queryParams.maxOutQty"-->
<!--          placeholder="请输入提币最大限制"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="提币最小限制" prop="minOutQty">-->
<!--        <el-input-->
<!--          v-model="queryParams.minOutQty"-->
<!--          placeholder="请输入提币最小限制"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="预警余额" prop="warningQty">-->
<!--        <el-input-->
<!--          v-model="queryParams.warningQty"-->
<!--          placeholder="请输入预警余额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="超过多少转入平台主地址" prop="outQtyToMainAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.outQtyToMainAddress"-->
<!--          placeholder="请输入超过多少转入平台主地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最小充值数量" prop="minRechargeQty">-->
<!--        <el-input-->
<!--          v-model="queryParams.minRechargeQty"-->
<!--          placeholder="请输入最小充值数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="同步到的区块高度" prop="syncBlockNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.syncBlockNumber"-->
<!--          placeholder="请输入同步到的区块高度"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="确认数" prop="confirmationsNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.confirmationsNum"-->
<!--          placeholder="请输入确认数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否显示" prop="isShow">-->
<!--        <el-input-->
<!--          v-model="queryParams.isShow"-->
<!--          placeholder="请输入是否显示"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否允许内转 0否 1可" prop="allowTransfer">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowTransfer"-->
<!--          placeholder="请输入是否允许内转 0否 1可"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="对内转账手续费" prop="inWithdrawFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.inWithdrawFee"-->
<!--          placeholder="请输入对内转账手续费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="内部转账手续费" prop="allowTransferFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowTransferFee"-->
<!--          placeholder="请输入内部转账手续费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单笔转账最小金额" prop="allowTransferMin">-->
<!--        <el-input-->
<!--          v-model="queryParams.allowTransferMin"-->
<!--          placeholder="请输入单笔转账最小金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="币种排序  针对获取地址  " prop="sort">-->
<!--        <el-input-->
<!--          v-model="queryParams.sort"-->
<!--          placeholder="请输入币种排序  针对获取地址  "-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['api:wCoin:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['api:wCoin:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['api:wCoin:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['api:wCoin:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wCoinList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="币种名称" align="center" prop="coinName" />
      <el-table-column label="简称" align="center" prop="shortName" />
      <el-table-column label="币种类型" align="center" prop="coinType"/>
      <el-table-column label="合约地址" align="center" prop="contract" />
      <el-table-column label="允许充值" align="center" prop="allowRecharge" :formatter="showAllowRecharge"/>
      <el-table-column label="允许提币" align="center" prop="allowWithdraw" :formatter="showAllowWithdraw" />
      <el-table-column label="对外转出手续费" align="center" prop="outWithdrawFee" />
      <el-table-column label="提币最大限制" align="center" prop="maxOutQty" />
      <el-table-column label="提币最小限制" align="center" prop="minOutQty" />
      <el-table-column label="是否允许内转" align="center" prop="allowTransfer" :formatter="showAllowTransfer"/>
      <el-table-column label="内部转账手续费" align="center" prop="allowTransferFee" />
      <el-table-column label="单笔转账最小金额" align="center" prop="allowTransferMin" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['api:wCoin:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['api:wCoin:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改币种配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="币种名称" prop="coinName">
          <el-input v-model="form.coinName" placeholder="请输入币种名称" />
        </el-form-item>
        <el-form-item label="简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入简称" />
        </el-form-item>
        <el-form-item label="币种图片" prop="coinImg">
          <el-input v-model="form.coinImg" placeholder="请输入币种图片" />
        </el-form-item>
<!--        <el-form-item label="超过多少数量转入冷钱包" prop="outQtyToColdAddress">-->
<!--          <el-input v-model="form.outQtyToColdAddress" placeholder="请输入超过多少数量转入冷钱包" />-->
<!--        </el-form-item>-->
        <el-form-item label="合约地址" prop="contract">
          <el-input v-model="form.contract" placeholder="请输入合约地址" />
        </el-form-item>
        <el-form-item label="币种精度 以太坊系列才有" prop="coinDecimal">
          <el-input v-model="form.coinDecimal" placeholder="请输入币种精度 以太坊系列才有" />
        </el-form-item>
        <el-form-item label="允许充值" prop="allowRecharge">
          <el-radio-group v-model="form.allowRecharge">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="允许提币" prop="allowWithdraw">
          <el-radio-group v-model="form.allowWithdraw">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否允许兑换" prop="allowExchange">
          <el-radio-group v-model="form.allowExchange">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="对外转出手续费" prop="outWithdrawFee">
          <el-input v-model="form.outWithdrawFee" placeholder="请输入对外转出手续费" />
        </el-form-item>
        <el-form-item label="提币最大限制" prop="maxOutQty">
          <el-input v-model="form.maxOutQty" placeholder="请输入提币最大限制" />
        </el-form-item>
        <el-form-item label="提币最小限制" prop="minOutQty">
          <el-input v-model="form.minOutQty" placeholder="请输入提币最小限制" />
        </el-form-item>
<!--        <el-form-item label="预警余额" prop="warningQty">-->
<!--          <el-input v-model="form.warningQty" placeholder="请输入预警余额" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="超过多少转入平台主地址" prop="outQtyToMainAddress">-->
<!--          <el-input v-model="form.outQtyToMainAddress" placeholder="请输入超过多少转入平台主地址" />-->
<!--        </el-form-item>-->
        <el-form-item label="最小充值数量" prop="minRechargeQty">
          <el-input v-model="form.minRechargeQty" placeholder="请输入最小充值数量" />
        </el-form-item>
        <el-form-item label="同步到的区块高度" prop="syncBlockNumber">
          <el-input v-model="form.syncBlockNumber" placeholder="请输入同步到的区块高度" />
        </el-form-item>
        <el-form-item label="确认数" prop="confirmationsNum">
          <el-input v-model="form.confirmationsNum" placeholder="请输入确认数" />
        </el-form-item>
<!--        <el-form-item label="是否显示" prop="isShow">-->
<!--          <el-input v-model="form.isShow" placeholder="请输入是否显示" />-->
<!--        </el-form-item>-->
        <el-form-item label="是否允许内转" prop="allowTransfer">
          <el-radio-group v-model="form.allowTransfer">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="对内转账手续费" prop="inWithdrawFee">
          <el-input v-model="form.inWithdrawFee" placeholder="请输入对内转账手续费" />
        </el-form-item>
        <el-form-item label="内部转账手续费" prop="allowTransferFee">
          <el-input v-model="form.allowTransferFee" placeholder="请输入内部转账手续费" />
        </el-form-item>
        <el-form-item label="单笔转账最小金额" prop="allowTransferMin">
          <el-input v-model="form.allowTransferMin" placeholder="请输入单笔转账最小金额" />
        </el-form-item>
        <el-form-item label="币种排序  针对获取地址  " prop="sort">
          <el-input v-model="form.sort" placeholder="请输入币种排序  针对获取地址  " />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWCoin, getWCoin, delWCoin, addWCoin, updateWCoin, exportWCoin } from "@/api/api/wCoin";

export default {
  name: "WCoin",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 币种配置表格数据
      wCoinList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        coinType: null,
        coinName: null,
        shortName: null,
        coinImg: null,
        outQtyToColdAddress: null,
        contract: null,
        coinDecimal: null,
        allowRecharge: null,
        allowWithdraw: null,
        allowExchange: null,
        outWithdrawFee: null,
        maxOutQty: null,
        minOutQty: null,
        warningQty: null,
        outQtyToMainAddress: null,
        minRechargeQty: null,
        syncBlockNumber: null,
        confirmationsNum: null,
        isShow: null,
        allowTransfer: null,
        inWithdrawFee: null,
        allowTransferFee: null,
        allowTransferMin: null,
        sort: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    showCoinType(row, column) {
      if (row.coinType === 1) {
        return '比特系'
      } else  {
        return '以太坊系列'
      }
    },
    showAllowRecharge(row, column) {
      if (row.allowRecharge === 1) {
        return '是'
      } else  {
        return '否'
      }
    },
    showAllowWithdraw(row, column) {
      if (row.allowWithdraw === 1) {
        return '是'
      } else  {
        return '否'
      }
    },
    showAllowTransfer(row, column) {
      if (row.allowTransfer === 1) {
        return '是'
      } else  {
        return '否'
      }
    },
    /** 查询币种配置列表 */
    getList() {
      this.loading = true;
      listWCoin(this.queryParams).then(response => {
        this.wCoinList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        coinType: null,
        coinName: null,
        shortName: null,
        coinImg: null,
        outQtyToColdAddress: null,
        contract: null,
        coinDecimal: null,
        allowRecharge: null,
        allowWithdraw: null,
        allowExchange: null,
        outWithdrawFee: null,
        maxOutQty: null,
        minOutQty: null,
        warningQty: null,
        outQtyToMainAddress: null,
        minRechargeQty: null,
        syncBlockNumber: null,
        confirmationsNum: null,
        isShow: null,
        allowTransfer: null,
        inWithdrawFee: null,
        allowTransferFee: null,
        allowTransferMin: null,
        sort: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加币种配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWCoin(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改币种配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWCoin(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWCoin(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除币种配置编号为"' + ids + '"的数据项？').then(function() {
        return delWCoin(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('api/wCoin/export', {
        ...this.queryParams
      }, `wCoin_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
